package com.atguigu.lease.web.admin.controller.lease;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.model.enums.AppointmentStatus;
import com.atguigu.lease.web.admin.service.ViewAppointmentService;
import com.atguigu.lease.web.admin.vo.appointment.AppointmentQueryDto;
import com.atguigu.lease.web.admin.vo.appointment.AppointmentVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "预约看房管理")
@RequestMapping("/admin/appointment")
@RestController
public class ViewAppointmentController {
  @Autowired private ViewAppointmentService viewAppointmentService;

  @Operation(summary = "分页查询预约信息")
  @GetMapping("page")
  public Result<IPage<AppointmentVo>> page(
          // FIXME: 2024/9/3 预约信息查询不显示省份
      @RequestParam long current, @RequestParam long size, AppointmentQueryDto queryVo) {
    IPage<AppointmentVo> page = new Page<>(current, size);
    IPage<AppointmentVo> list = viewAppointmentService.pageAppointmentByQuery(page, queryVo);
    return Result.ok(list);
  }

  @Operation(summary = "根据id更新预约状态")
  @PostMapping("updateStatusById")
  public Result updateStatusById(@RequestParam Long id, @RequestParam AppointmentStatus status) {
    boolean flag =
        viewAppointmentService.update(
            Wrappers.lambdaUpdate(ViewAppointment.class)
                .eq(ViewAppointment::getId, id)
                .set(ViewAppointment::getAppointmentStatus, status));
    return Result.build(flag);
  }
}
